package afcp.alumni.email;

import java.util.Locale;

import javax.mail.MessagingException;

import afcp.alumni.action.base.BaseAction;
import afcp.alumni.model.db.Member;

public class PasswordEmail extends Email {

	public PasswordEmail(Member member, String password, Locale locale)
			throws MessagingException {
		if (member.getEmail() == null || member.getEmail().isEmpty()) {
			throw new IllegalStateException("The member email cannot be empty. Member: " + member.getId());
		}
		
		String object = BaseAction.msg(locale, "email.password.object");
		// TODO get template depending on chosen locale.
		String[] htmlTxt = MailTemplate.getPasswordTemplateHtmlTxt(
				member.getFirstName(), member.getId(), password);
		String bodyHtml = htmlTxt[0];
		String bodyTxt = htmlTxt[1];
		super.init(member.getEmail(),
				member.getFirstName() + " " + member.getLastName(), object,
				bodyHtml, bodyTxt, locale);
	}

	public void init(String recipientEmail, String recipientName,
			String subject, String body) throws MessagingException {
		throw new IllegalStateException("email already initialized. "
				+ "When using PasswordEmail, the "
				+ "init() method mustn't be called.");
	}

}
